package com.wenhao.newcode.huawei.medium2016;

import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-07-21 13:21
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            if (n > 999) {
                n = 999;
            }
            int index = 1;
            for (int i = 2;i < n;i++) {
                index =  (index + 3) % i;
            }
            System.out.println(index);
        }
    }
}
